package edu.study.module.student.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.ultrawise.survey.core.base.BaseDao;
import com.ultrawise.survey.module.surevybase.vo.TSurveyInfoQuestion;

import edu.study.module.student.vo.StudentInfo;

@Repository
public class StudentInfoDAO extends BaseDao {

	public List<StudentInfo> query(StudentInfo st) {
		String sql = "select * from " + st.getTableName() + " a where 1 = 1 ";
		Object[] params = new Object[7];
		int index = 0;
		if (!StringUtils.isEmpty(st.getSt_name())) {
			sql += " and ST_NAME LIKE ?";
			params[index] = "%" + st.getSt_name() + "%";
			index++;
		}

		if (!StringUtils.isEmpty(st.getSt_class())) {
			sql += " and ST_CLASS LIKE ?";
			params[index] = "%" + st.getSt_class() + "%";
			index++;
		}
		Object[] paramsEnd = new Object[index];
		System.arraycopy(params, 0, paramsEnd, 0, index);
		List<StudentInfo> ls =new ArrayList<StudentInfo>();
		try {
			ls = getJdbcTemplate().query(sql, paramsEnd, new BeanPropertyRowMapper(StudentInfo.class));
			System.out.println("ls:" + ls.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ls;
	}
}
